<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/26
 * Time: 13:45
 */

namespace common\consts;

use common\helpers\StringUtil;
use Yii;

/**
 * Class CommonResources 多语言类，具体翻译参见messages/zh-CN/app.php
 * 注意： 里面的string 值必须和多语言包内的一模一样
 * @package common\consts
 */
class CommonResources
{
    const NO = 'No';
    const IS_NOT = 'Is Not';

    const SUBJECT_PREDICATE_OBJECT = '{subject} {predicate} {object}';
    const SUBJECT_WITH_NAME_PREDICATE_OBJECT = '{subject} : [{name}] {predicate} {object}';

    const BATCH_DELETE = 'Batch Delete';

    const ACTION_NAME_MODEL = '{action} {modelClass} : [{name}]';
    public static function ACTION_NAME_MODEL($actionName, $modelName, $objName){
        return Yii::t('app', self::ACTION_NAME_MODEL, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
            'name' => Yii::t('app', $objName),
        ]);
    }

    const ACTION_NAME_MODEL_SUCCESS = '{action} {modelClass} : [{name}] Success.';
    public static function ACTION_NAME_MODEL_SUCCESS($actionName, $modelName, $objName){
        return Yii::t('app', self::ACTION_NAME_MODEL_SUCCESS, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
            'name' => Yii::t('app', $objName),
        ]);
    }

    const ACTION_NAME_MODEL_SUCCESS_DETAIL = '{action} {modelClass} : [{name}] Success, {detail}.';
    public static function ACTION_NAME_MODEL_SUCCESS_DETAIL($actionName, $modelName, $objName, $detailMsg){
        return Yii::t('app', self::ACTION_NAME_MODEL_SUCCESS_DETAIL, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
            'name' => Yii::t('app', $objName),
            'detail' => Yii::t('app', $detailMsg),
        ]);
    }

    const ACTION_NAME_MODEL_FAIL = '{action} {modelClass} : [{name}] Fail.';
    public static function ACTION_NAME_MODEL_FAIL($actionName, $modelName, $objName, $failReason = null){
        if (StringUtil::isNullOrWhiteSpace($failReason)){
            return Yii::t('app', self::ACTION_NAME_MODEL_FAIL, [
                'action' => Yii::t('app', $actionName),
                'modelClass' => Yii::t('app', $modelName),
                'name' => Yii::t('app', $objName),
            ]);
        }
        return Yii::t('app', self::ACTION_NAME_MODEL_FAIL_WITH_REASON, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
            'name' => Yii::t('app', $objName),
            'failReason' => Yii::t('app', $failReason),
        ]);
    }

    const ACTION_NAME_MODEL_FAIL_WITH_REASON = '{action} {modelClass} : [{name}] Fail, reason: {failReason}';
    public static function ACTION_NAME_MODEL_FAIL_WITH_REASON($actionName, $modelName, $name, $failReason){
        return Yii::t('app', self::ACTION_NAME_MODEL_FAIL_WITH_REASON, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
            'name' =>  Yii::t('app', $name),
            'failReason' => Yii::t('app', $failReason),
        ]);
    }

    const ACTION_MSG = '{action} {modelClass}';
    public static function ACTION_MSG($actionName, $modelName) {
        return Yii::t('app', self::ACTION_MSG, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
        ]);
    }

    const ACTION_NAME_MSG = '{action} {modelClass} : {name}';
    public static function ACTION_NAME_MSG($actionName, $modelName, $name) {
        return Yii::t('app', self::ACTION_NAME_MSG, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
            'name' => Yii::t('app', $name),
        ]);
    }

    const ACTION_SUCCESS_MSG = '{action} {modelClass} Success.';
    public static function ACTION_SUCCESS_MSG($actionName, $modelName){
        return Yii::t('app', self::ACTION_SUCCESS_MSG, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
        ]);
    }

    const ACTION_SUCCESS_MSG_DETAIL = '{action} {modelClass} Success, {detail}.';
    public static function ACTION_SUCCESS_MSG_DETAIL($actionName, $modelName, $detailMsg){
        return Yii::t('app', self::ACTION_SUCCESS_MSG_DETAIL, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
            'detail' => Yii::t('app', $detailMsg),
        ]);
    }

    const ACTION_FAIL_MSG = '{action} {modelClass} Fail, reason: {failReason}.';
    public static function ACTION_FAIL_MSG($actionName, $modelName, $failReason){
        return Yii::t('app', self::ACTION_FAIL_MSG, [
            'action' => Yii::t('app', $actionName),
            'modelClass' => Yii::t('app', $modelName),
            'failReason' => Yii::t('app', $failReason),
        ]);
    }

    const ATTRIBUTE_CHANGED = '{attribute} changed, Old: {oldValue}, New：{newValue}.';
    public static function ATTRIBUTE_CHANGED($attrKey, $attrOldValue, $attrNewValue){
        return  Yii::t('app', self::ATTRIBUTE_CHANGED, [
            'attribute' => $attrKey,
            'oldValue' => $attrOldValue,
            'newValue' => $attrNewValue
        ]);
    }
    const ATTRIBUTE_ADDED = '{attribute} added, New：{newValue}.';
    public static function ATTRIBUTE_ADDED($attrKey, $attrValue){
        return  Yii::t('app', self::ATTRIBUTE_ADDED, [
            'attribute' => $attrKey,
            'newValue' => $attrValue,
        ]);
    }
    const ATTRIBUTE_DELETED = '{attribute} deleted, Old：{oldValue}.';
    public static function ATTRIBUTE_DELETED($attrKey, $attrValue){
        return  Yii::t('app', self::ATTRIBUTE_DELETED, [
            'attribute' => $attrKey,
            'oldValue' => $attrValue,
        ]);
    }
    const ATTR_KEY_VALUE = '{attribute} : {attrValue}.';
    public static function ATTRIBUTE_KEY_VALUE($attrKey, $attrValue){
        return  Yii::t('app', self::ATTR_KEY_VALUE, [
            'attribute' => $attrKey,
            'attrValue' => $attrValue,
        ]);
    }

    const RESULT_SUMMARY_MESSAGE = 'TotalCount : {total_count} , Success : {success_count} , Fail : {fail_count} , Skipped : {skipped_count}.';
    /**
     * @param $totalCount integer
     * @param int $successCount integer
     * @param int $failCount integer
     * @param int $skipCount integer
     * @return string
     */
    public static function RESULT_SUMMARY_MESSAGE($totalCount, $successCount = 0, $failCount = 0, $skipCount = 0) {
        if ($failCount == 0 && $skipCount == 0){
            $successCount = $totalCount;
        }

        return Yii::t('app', self::RESULT_SUMMARY_MESSAGE, [
            'total_count' => $totalCount,
            'success_count' => $successCount,
            'fail_count' => $failCount,
            'skipped_count' => $skipCount,
        ]);
    }

    const OBJECT_NOT_CHANGED_PARAMS = '{object} not changed.';
    public static function OBJECT_NOT_CHANGED($objName){
        return Yii::t('app', self::OBJECT_NOT_CHANGED_PARAMS, [
            'object' => Yii::t('app',$objName),
        ]);
    }

    const OBJECT_NOT_FOUND_PARAMS = '{object} not found.';
    public static function OBJECT_NOT_FOUND($objName){
        return Yii::t('app', self::OBJECT_NOT_FOUND_PARAMS, [
            'object' => Yii::t('app',$objName),
        ]);
    }

    const PLS_SELECT = '===Pls Select===';
    public static function PROMPT_PLS_SELECT(){
        return Yii::t('app', self::PLS_SELECT);
    }

    const NO_JSON_CONTENT_FOUND = 'No Json Content Found';
    public static function  NO_JSON_CONTENT_FOUND(){
        return Yii::t('app', self::NO_JSON_CONTENT_FOUND);
    }

    const NOT_SET = '(Not Set)';
    public static function NOT_SET(){
        return  Yii::t('app', self::NOT_SET);
    }

    const IS_NOT_JSON_FORMAT = 'Is Not Json Format';
    public static function IS_NOT_JSON_FORMAT(){
        return Yii::t('app', self::IS_NOT_JSON_FORMAT);
    }

    public static function PARAMS_CHECK_PASSED(){
        return Yii::t('app', 'Params Check Passed');
    }

    public static function CODE_NOT_SUPPORTED($code){
        return Yii::t('app', self::SUBJECT_WITH_NAME_PREDICATE_OBJECT, [
            'subject' => Yii::t('app', 'Code'),
            'name' => $code,
            'predicate' => Yii::t('app', self::IS_NOT),
            'object' => Yii::t('app', 'Supported'),
        ]);
    }
}